package com.sp.fresh_produce.controller;

import com.github.pagehelper.PageInfo;
import com.sp.fresh_produce.common.GenericReturnApiObject;
import com.sp.fresh_produce.service.OrderService;
import com.sp.fresh_produce.web.AdminRequired;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *  订单后台管理
 */
@RestController
@RequestMapping("/admin")
public class OrderAdminController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/orderList")
    @Operation(summary = "管理员订单列表")
    @AdminRequired
    public GenericReturnApiObject getOrdersListForAdmin(@RequestParam Integer pageNum, @RequestParam Integer pageSize)
    {
        PageInfo pageInfo = orderService.listForAdmin(pageNum, pageSize);
        return GenericReturnApiObject.success(pageInfo);
    }


    /**
     * 管理员发货
     */
    @PostMapping("/delivered")
    @Operation(summary = "管理员发货")
    public GenericReturnApiObject delivered(@RequestParam String orderNo) {
        orderService.delivered(orderNo);
        return GenericReturnApiObject.success();
    }
}
